package com.patrol.auth.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.patrol.auth.pojo.AdminUser;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 * @author 宋灿
 * @version 1.0
 * @description: TODO
 * @date 2021/8/12 16:37
 */
@Mapper
@Repository
public interface AdminUserDao extends BaseMapper<AdminUser> {
    //注册成功，插入一条数据
    //@Insert("insert into admin_user(username,password,authority) values (#{username},#{password},#{authority})")
    // int add(AdminUser user);
    //检验注册的username是否已经存在数据库中，通过User类创建findByUsername对象，传进username进行与数据库比较
    @Select("select * from admin_user where username = #{username}")
    AdminUser findByUsername(@Param("username") String username);
    //登录用：检验账号密码是否正确
    @Select("select * from admin_user where username = #{username} and password = #{password}")
    AdminUser findByUsername_login(@Param("username") String username,
                                   @Param("password") String password);
    //修改个人信息
    @Update("update admin_user set realName = #{user.realName}, password = #{user.password}, sex= #{user.sex}, email=#{user.email},tel=#{user.tel} WHERE username = #{username}")
    Integer updateUser(AdminUser user,@Param("username") String username);
    //添加管理员头像
    @Update("update admin_user set img = #{url} where username = #{username}")
    Integer updatePhotoUrl(@Param("username") String username, @Param("url") String url);
    //检验注册的img是否已经存在数据库中，通过User类创建findByUrl对象，传进url进行与数据库比较
    @Select("select * from admin_user where img = #{url}")
    AdminUser findByUrl(@Param("url") String url);

    @Select("select img from admin_user where username=#{username}")
    String selectUserImgUrl(String username);

    @Update("update admin_user set password = #{pwd} where email = #{email}")
    boolean updatePwd(String pwd,String email);
}
